package com.bulletelc.apollopre.module.main.center.afterSale.detail;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bulletelc.apollopre.R;
import com.bulletelc.apollopre.entity.ServiceOrderGoodBean;
import com.bumptech.glide.Glide;

import java.util.List;

/**
 * Created by CX on 2018/1/27.
 */

public class GoodsListAdapter extends BaseAdapter {

    private Context context;
    private List<ServiceOrderGoodBean> sogList;
    private LayoutInflater inflater;

    public GoodsListAdapter(Context context, List<ServiceOrderGoodBean> sogList) {
        this.context = context;
        this.sogList = sogList;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return sogList.size();
    }

    @Override
    public Object getItem(int i) {
        return sogList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ServiceOrderGoodBean sog = sogList.get(i);
        ViewHolder holder;
        holder = new ViewHolder();
        view = inflater.inflate(R.layout.service_order_list_child, viewGroup, false);
        holder.ivImg = view.findViewById(R.id.iv_good_img);
        holder.tvName = view.findViewById(R.id.tv_good_name);
        holder.tvSku = view.findViewById(R.id.tv_good_sku);
        holder.tvPrice = view.findViewById(R.id.tv_good_price);
        holder.tvQuantity = view.findViewById(R.id.tv_good_quantity);

        Glide.with(context).load(sog.getLogo_url()).into(holder.ivImg);
        holder.tvName.setText(sog.getProduct_name());
        holder.tvSku.setText(sog.getProduct_sku_title());
        holder.tvPrice.setText("¥"+sog.getReturn_price());
        holder.tvQuantity.setText("x"+sog.getQuantity());
        return view;
    }

    class ViewHolder {
        ImageView ivImg;
        TextView tvName,tvSku,tvPrice,tvQuantity;
    }
}
